﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mogre;

namespace ProjetSMA.View.Mogre
{
    public class Main : Base
    {
        private Map mTerrain;
        private LoadingBar loadingBar = new LoadingBar();
        private Map3D m_map_3D;
        private CameraTracker m_camera_tracker;
        private Entity3D m_first_entity;

        public override void CreateScene()
        {

            camera.Position = new Vector3(100, 150, 100);
            camera.LookAt(new Vector3(1000, -100, 1000));
            camera.NearClipDistance = 0.1f;
            camera.FarClipDistance = 8860;

           

            mTerrain = new Map(sceneMgr, root, viewport);
            mTerrain.CreateTerrain();

            SceneNode node = sceneMgr.RootSceneNode.CreateChildSceneNode();

            m_map_3D = new Map3D(sceneMgr, root);

            if (m_map_3D.ElementsMove[0] != null)
                m_camera_tracker = new CameraTracker(sceneMgr, root, m_map_3D.ElementsMove[0], "tracker");
            else
                m_camera_tracker = new CameraTracker(sceneMgr, root, new Entity3D(m_map_3D, null, root, sceneMgr, "_err", 0), "tracker");
            m_camera_tracker.Initialisation();   

        }

        private bool TestElement(object o)
        {
            if (o is Rock3D)
                return true;  
            return false;
        }

        public override void HideAllPattern()
        {
            foreach (Entity3D loc_entity in m_map_3D.ElementsMove)
            {
                loc_entity.PatternDisplay = false;
                loc_entity.Pattern.Destroy();
            }
        }

        public override void DisplayAllPattern()
        {
            foreach (Entity3D loc_entity in m_map_3D.ElementsMove)
            {
                loc_entity.PatternDisplay = true;
            }
        }


        protected override void ChangeCameraTrack()
        {
            viewport.Camera = m_camera_tracker.Camera;
        }

        protected override void DefaultCamera()
        {
            viewport.Camera = camera;
        }
           
        public override void DestroyScene()
        {
           // mTerrain.DestroyMap();
        }
    }
}
